#!/usr/bin/env python3
"""
GT-LMS 用户数据生成器
生成符合项目规范的展示用途用户数据，要求登陆输入的邮箱和密码简短
"""

import json
import os
from datetime import datetime
from typing import Dict, List, Any

# 用户数据目录
DATA_DIR = os.path.join(os.path.dirname(__file__), 'gt_lms', 'data')
USERS_FILE = os.path.join(DATA_DIR, 'users.json')

def generate_user_data() -> Dict[str, Any]:
    """生成用户数据"""
    return {
        # 管理员用户
        "admin_001": {
            "user_id": "admin_001",
            "name": "系统管理员",
            "email": "admin@gt.com",
            "_password": "admin123",
            "role": "admin",
            "created_at": datetime.now().isoformat(),
            "last_login": datetime.now().isoformat(),
            "is_active": True,
            "admin_level": 10,
            "permissions": [
                "view_courses", "view_users", "view_system_stats", "generate_reports",
                "create_user", "update_user", "delete_user", "manage_user_permissions",
                "create_course", "update_course", "delete_course", "manage_course_permissions",
                "backup_system", "restore_system", "system_maintenance", "view_system_logs",
                "super_admin", "manage_all_admins", "system_configuration"
            ]
        },
        
        # 教师用户
        "teacher_001": {
            "user_id": "teacher_001",
            "name": "张老师",
            "email": "zhang@gt.com",
            "_password": "teach123",
            "role": "teacher",
            "created_at": datetime.now().isoformat(),
            "last_login": datetime.now().isoformat(),
            "is_active": True,
            "employee_id": "T001",
            "department": "计算机科学系",
            "office_hours": "周一、周三 14:00-16:00",
            "courses_taught": ["course_001", "course_002"]
        },
        
        "teacher_002": {
            "user_id": "teacher_002",
            "name": "李教授",
            "email": "li@gt.com",
            "_password": "teach123",
            "role": "teacher",
            "created_at": datetime.now().isoformat(),
            "last_login": datetime.now().isoformat(),
            "is_active": True,
            "employee_id": "T002",
            "department": "软件工程系",
            "office_hours": "周二、周四 10:00-12:00",
            "courses_taught": ["course_003", "course_004"]
        },
        
        "teacher_003": {
            "user_id": "teacher_003",
            "name": "王老师",
            "email": "wang@gt.com",
            "_password": "teach123",
            "role": "teacher",
            "created_at": datetime.now().isoformat(),
            "last_login": datetime.now().isoformat(),
            "is_active": True,
            "employee_id": "T003",
            "department": "数据科学系",
            "office_hours": "周五 14:00-17:00",
            "courses_taught": ["course_005"]
        },
        
        # 学生用户
        "student_001": {
            "user_id": "student_001",
            "name": "张三",
            "email": "zhang@stu.com",
            "_password": "stu123",
            "role": "student",
            "created_at": datetime.now().isoformat(),
            "last_login": datetime.now().isoformat(),
            "is_active": True,
            "student_number": "S2023001",
            "major": "计算机科学与技术",
            "enrolled_courses": ["course_001", "course_003"],
            "gpa": 3.8,
            "grades": {"course_001": 90.5, "course_003": 85.0}
        },
        
        "student_002": {
            "user_id": "student_002",
            "name": "李四",
            "email": "li@stu.com",
            "_password": "stu123",
            "role": "student",
            "created_at": datetime.now().isoformat(),
            "last_login": datetime.now().isoformat(),
            "is_active": True,
            "student_number": "S2023002",
            "major": "软件工程",
            "enrolled_courses": ["course_002", "course_004"],
            "gpa": 3.6,
            "grades": {"course_002": 88.0, "course_004": 82.5}
        },
        
        "student_003": {
            "user_id": "student_003",
            "name": "王五",
            "email": "wang@stu.com",
            "_password": "stu123",
            "role": "student",
            "created_at": datetime.now().isoformat(),
            "last_login": datetime.now().isoformat(),
            "is_active": True,
            "student_number": "S2023003",
            "major": "数据科学",
            "enrolled_courses": ["course_005"],
            "gpa": 3.9,
            "grades": {"course_005": 92.0}
        },
        
        "student_004": {
            "user_id": "student_004",
            "name": "赵六",
            "email": "zhao@stu.com",
            "_password": "stu123",
            "role": "student",
            "created_at": datetime.now().isoformat(),
            "last_login": datetime.now().isoformat(),
            "is_active": True,
            "student_number": "S2023004",
            "major": "人工智能",
            "enrolled_courses": ["course_001", "course_005"],
            "gpa": 3.7,
            "grades": {"course_001": 87.5, "course_005": 89.0}
        },
        
        "student_005": {
            "user_id": "student_005",
            "name": "钱七",
            "email": "qian@stu.com",
            "_password": "stu123",
            "role": "student",
            "created_at": datetime.now().isoformat(),
            "last_login": datetime.now().isoformat(),
            "is_active": True,
            "student_number": "S2023005",
            "major": "网络安全",
            "enrolled_courses": ["course_002", "course_003", "course_004"],
            "gpa": 3.5,
            "grades": {"course_002": 85.0, "course_003": 80.5, "course_004": 86.0}
        }
    }

def save_user_data(data: Dict[str, Any]) -> None:
    """保存用户数据到文件"""
    try:
        # 确保数据目录存在
        os.makedirs(DATA_DIR, exist_ok=True)
        
        # 保存数据到JSON文件
        with open(USERS_FILE, 'w', encoding='utf-8') as f:
            json.dump(data, f, indent=2, ensure_ascii=False, default=str)
        
        print(f"用户数据已成功保存到: {USERS_FILE}")
    except Exception as e:
        print(f"保存用户数据时出错: {e}")

def print_user_credentials() -> None:
    """打印用户登录凭据"""
    print("\n=== GT-LMS 系统用户登录凭据 ===\n")
    
    print("管理员账户:")
    print("邮箱: admin@gt.com")
    print("密码: admin123")
    print()
    
    print("教师账户:")
    print("1. 邮箱: zhang@gt.com, 密码: teach123")
    print("2. 邮箱: li@gt.com, 密码: teach123")
    print("3. 邮箱: wang@gt.com, 密码: teach123")
    print()
    
    print("学生账户:")
    print("1. 邮箱: zhang@stu.com, 密码: stu123")
    print("2. 邮箱: li@stu.com, 密码: stu123")
    print("3. 邮箱: wang@stu.com, 密码: stu123")
    print("4. 邮箱: zhao@stu.com, 密码: stu123")
    print("5. 邮箱: qian@stu.com, 密码: stu123")
    print()

def main():
    """主函数"""
    print("正在生成GT-LMS系统用户数据...")
    
    # 生成用户数据
    user_data = generate_user_data()
    
    # 保存用户数据
    save_user_data(user_data)
    
    # 打印登录凭据
    print_user_credentials()
    
    print("用户数据生成完成！")

if __name__ == "__main__":
    main()